<?php
declare(strict_types=1);
/**
 * Created by PhpStorm
 * User: Administrator
 * Date: 2023/4/11
 * Time: 14:16:56
 */

namespace Service\Code;

class Billcode
{
    public static function returnCode($type,$mn_sid) {
        return $type.date('YmdHis').$mn_sid. self::random(4, '0123456789');
    }

    /**
     * 获取指定长度的随机字母数字组合的字符串
     *
     * @param  int $length
     * @return string
     */
    public static function random($length = 16,string $pool = '')
    {
        $pool = !empty($pool) ? $pool : '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

        return self::Str(str_shuffle(str_repeat($pool, $length)), 0, $length);
    }

    public static function Str($string, $start, $length = null){
        return mb_substr($string, $start, $length, 'UTF-8');
    }
}